#include "stdafx.h"
#include <MyControls/ZoomSlider.h>
#include <MyControls/Resource.h>
#include <MyControls/App.h>
#include <cmath>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

namespace My {

ZoomSlider::ZoomSlider()
	: m_pView(0)
{
	m_MinScale = 0.25;
	m_MaxScale = 16;
	SetEnabled(false);
}

String ZoomSlider::Hint() const
{ 
	return GetApp().LoadString(IDS_ZOOM); 
}

void ZoomSlider::SetView(ZoomView * pView)
{
	if (pView != m_pView) {
		m_pView = pView;
		SetEnabled(m_pView != 0);
	}
}

void ZoomSlider::SetValue(double value)
{
	if (m_pView == 0)
		return;
	double min = m_MinScale, max = m_MaxScale;
	if (max > min)
		m_pView->Zoom((float) (min * pow(max / min, value)));
}

double ZoomSlider::GetValue() const
{
	if (m_pView == 0)
		return 0;
	double s = m_pView->GetScale(), min = m_MinScale, max = m_MaxScale;
	if (max > min)
		return log(s / min) / log(max / min);
	else
		return 0;
}

void ZoomSlider::HandleUpdateUI()
{
	Invalidate();
}

} // My